package cn.wit.db.aspect;

import cn.wit.db.entity.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class DefaultExeptionHandler {
	private Logger logger = LoggerFactory.getLogger(DefaultExeptionHandler.class);

	
	@ExceptionHandler(AccessDeniedException.class)
	@ResponseBody
	@ResponseStatus(code = HttpStatus.FORBIDDEN)
	public AjaxResult handleAccessDeniedExeption(AccessDeniedException e) {
		return new AjaxResult(403, e.getMessage());
	}

	/**
	 * 处理其它异常
	 * 
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public String handleGeneralException(Exception e) {
		logger.error("未知的服务器异常", e);
		
		return "/error/500";
	}
}
